package com.apes.fn.business.insurance.modle;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.soe.annotations.State;
import com.apes.framework.plugin.soe.annotations.States;
import com.apes.framework.plugin.soe.metadata.BusinessAttributeValue;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.MapUtil;
import com.apestech.framework.json.JSONObject;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Map;

/**
 * @ClassName : PolicyInformationItem
 * @Description : 保单明细
 * @Author : WSJ
 * @Date: 2020-04-28 15:59
 */
@Getter
@Setter
@Entity
@Table(name = PolicyInformationItem.CONST_TABLE_NAME,indexes = {@Index(name = "u_policy_information_item",columnList =
        "policy_Information_id,commission_Type")})
@SelectBeforeUpdate
@DynamicUpdate
@DynamicInsert
@EntityListeners(DefaultPersistListener.class)
public class PolicyInformationItem extends BaseModel {
    public static final String CONST_TABLE_NAME = "policy_information_item";

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "佣金明细", padding = 4)
    @Comment("ID")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "policy_Information_id",nullable = false,referencedColumnName = "id")
    @Comment("保单号")
    private PolicyInformation policyInformation;

    @Column(name = "settlement",columnDefinition = ApesConst.FIELD_BOOLEAN_FALSE)
    @Comment("佣金对账标记")
    private boolean settlement = false;

    @States(name = "佣金类型", values = {
            @State(id = "A", name = "正常佣金"),
            @State(id = "B", name = "追加佣金"),
            @State(id = "C", name = "退保佣金"),
            @State(id = "D", name = "退保追加佣金")
    })
    @Comment("佣金类型")
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "commission_type", nullable = false, referencedColumnName = "id")
    private BusinessAttributeValue commissionType;

    @Comment("佣金比率")
    @Column(name = "commission_Ratio",nullable = false, columnDefinition = ApesConst.FIELD_ROUND_16_8)
    private double commissionRatio = 0;


    @Comment("佣金金额")
    @Column(name = "commission",nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double commission = 0 ;

    @Comment("赋能佣金金额")
    @Column(name = "fn_commission",nullable = false, columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double fnCommission = 0 ;

    @Comment("赋能佣金比率")
    @Column(name = "fn_commission_Ratio",nullable = false, columnDefinition = ApesConst.FIELD_ROUND_16_8)
    private double fnCommissionRatio = 0;

    @Comment("勾兑金额")
    @Column(name = "blend_Amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double blendAmount = 0;

    @Comment("未勾兑金额")
    @Column(name = "not_Blend_Amount", columnDefinition = ApesConst.FIELD_MONEY_16_4_0)
    private double notBlendAmount = 0;

    @Column(name = "platform_management_fee", nullable = false, columnDefinition = ApesConst.FIELD_16_4_0)
    @Comment("平台管理费")
    private double platformManagementFee = 0;

    @Comment("修改标记")
    @Column(name = "fix_state")
    private String fixState ;//1为修改中 修改完成设置为空

    public Map getPolicyInfo() {
//        return MapUtil.mapper("id",this.policyInformation.getId(),
//                "plateLicense",this.policyInformation.getPlateLicense(),
//                "dept",this.policyInformation.getDept().getName(),
//                "insuranceAmount",this.policyInformation.getInsuranceAmount(),
//                "supplier",this.policyInformation.getSupplier().getName());
        return MapUtil.mapped(this.policyInformation,"policyInformationItems");
    }

    public void setPolicyInfo(Map policyInfo) {
        return;
    }

    @Transient
    private Map policyInfo;


    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }
}
